<?php
include_once 'check_functions.php';
include_once 'data_layer.php';

if (!isset($_GET['pid'])) {
    echo "<p style='color:red;'>Please provide a PID</p>";
    die();
}
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Check Participants</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Bootstrap -->
        <link href="assets/js/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <!-- Main -->
        <link href="main.css" rel="stylesheet" media="screen">

    </head>

    <body>

        <!-- Part 1: Wrap all page content here -->
        <!-- Begin page content -->
        <div class="container">
            <ul>
                <?php
                $pid = $_GET['pid'];

                $pidExists = participantExists($pid);

                $ptFilledout = hasFilledout($pid, "personality_traits");
                $ptPassed = hasPassedCheats($pid, "personality_traits");

                $imiqFilledout = hasFilledout($pid, "imiq");
                $imiqPassed = hasPassedCheats($pid, "imiq");

                $motivationFilledout = hasFilledout($pid, "motivational_factors");
                $motivationPassed = hasPassedCheats($pid, "motivational_factors");

                $backgroundFilledout = hasFilledout($pid, "background");

                $recipeURL = getRecipeURL($pid);


                echo "<li style='color:" . ($pidExists ? "green" : "red") . ";'>PID " . ($pidExists ? "is valid</li>" : "is not valid</li>");
                echo "<li style='color:" . ($ptFilledout && $ptPassed ? "green" : "red") . ";'>Personality test " . ($ptFilledout && $ptPassed ? "has been filled out correctly</li>" : "hasn't been filled out correctly</li>");
                echo "<li style='color:" . ($imiqFilledout && $imiqPassed ? "green" : "red") . ";'>IMI questionnaire " . ($imiqFilledout && $imiqPassed ? "has been filled out correctly</li>" : "hasn't been filled out correctly</li>");
                echo "<li style='color:" . ($motivationFilledout && $motivationPassed ? "green" : "red") . ";'>Motivational factors questionnaire " . ($motivationFilledout && $motivationPassed ? "has been filled out correctly</li>" : "hasn't been filled out correctly</li>");
                echo "<li style='color:black;'> Recipe URL: <a target='_blank' href='" . $recipeURL . "'>" . $recipeURL . "</a></li>";
                ?>
            </ul>
        </div>
    </body>
</html>